package com.siwei.mes.enums;

import com.siwei.mes.common.exception.BizException;
import lombok.Getter;

import java.util.Arrays;

/**
 * @Author Administrator
 * @Date 2023/7/21 15:21
 * @Version 1.0
 * @Description 比较符号 枚举  1-大于 2-大于等于  3-等于 4-不等于 5-小于  6-小于等于
 */
@Getter
public enum CompareEnum {
    GT(1, "> ", "大于"),
    GT_AND_EQ(2, ">= ", "大于等于"),
    EQ(3, "== ", "等于"),
    NOT_EQ(4, "!= ", "不等于"),
    LT(5, "< ", "小于"),
    LT_AND_EQ(6, "<= ", "小于等于"),
    AND(7, " && ", "并且"),
    OR(8, " || ", "或"),
    VAL(9, "val ", "变量"),
    ;
    private Integer code;

    private String name;

    private String desc;

    /**
     * 查找枚举信息
     *
     * @param code
     * @return
     */
    public static CompareEnum selectByCode(Integer code) {
        return Arrays.stream(values()).filter(e -> e.getCode().equals(code)).findFirst()
                .orElseThrow(() -> new BizException("该比较符号枚举类型不存在"));
    }

    CompareEnum(Integer code, String name, String desc) {
        this.code = code;
        this.name = name;
        this.desc = desc;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }
}
